package graphclustering;

import graphclustering.algorithm.BitClusteringAlgorithm;
import graphclustering.algorithm.IterativeAnalysisAlgorithm;
import graphclustering.data.Cluster;
import graphclustering.data.DWGraph;
import graphclustering.data.LoadandSave;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class Main {
    private static Log logger = LogFactory.getLog(Main.class);

    public static void main(String[] args) {
        try {
            if (args.length == 3) {
                if (args[0].equals("Iter")) {
                    DWGraph graph1 = LoadandSave.loadGraphFromFile(args[1]);
                    logger.debug("Finish loading dw graph from file[="
                            + args[1] + "]");
                    Cluster result1 = IterativeAnalysisAlgorithm
                            .analysis(graph1);
                    logger.debug("Finish clustring process");
                    LoadandSave.saveResultToFile(args[2], result1);
                    logger.debug("Save result to file[=" + args[2] + "]");

                } else if (args[0].equals("Bit")) {
                    DWGraph graph = LoadandSave.loadGraphFromFile(args[1]);
                    logger.debug("Finish loading dw graph from file[="
                            + args[1] + "]");
                    Cluster result = new Cluster();
                    BitClusteringAlgorithm.analysis(graph, result);
                    logger.debug("Finish clustring process");
                    LoadandSave.saveResultToFile(args[2], result);
                    logger.debug("Save result to file[=" + args[2] + "]");
                    logger.debug("BitClusteringAlgo all run "
                            + BitClusteringAlgorithm.rounds + " rounds");
                }
            } else {
                System.out
                        .println("The command format should as following: Main AlgorithmType InputGraph OutputResult");
            }
        } catch (Exception e) {
            System.out.println("Exception:" + e.toString());
        }
        return;
    }

}
